/*
 * mycrawl.h
 *
 *  Created on: 2011-10-27
 *      Author: liujian
 */

#ifndef MYCRAWL_H_
#define MYCRAWL_H_
#include<stdio.h>
#include<errno.h>
#include<queue>
#include<pthread.h>
#include<stdlib.h>
#include<pthread.h>
#include<fcntl.h>
#include<sys/time.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<sys/types.h>
#include<netdb.h>
#include<boost/regex.hpp>
#include<regex.h>
#include<string>//string class
#include<string.h>//memset
#include<strings.h>
#include<sys/mman.h>
#include<pcre.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>

#include"http_uri.h"
#include"http_resp.h"
#include"bloomfilter.h"
#include"html.h"
#include"tidy.h"
#include"buffio.h"
#include"log.h"


using namespace std;

typedef struct _rev_buf{
	char *buf_src;
	int buf_size;
	int buf_left;
}resp_packet_buf;

typedef enum {
		REQUEST_IP_TABLE_CMD,
		RESPONSE_IP_TABLE_CMD,
		WAITING_HEARTBEAT_CMD,
		RESPONSE_HEARTBEAT_CMD,
		BROADCAST_JOIN_CMD,
		BROADCAST_EXIT_CMD
}packet_cmd;

const int OVECCOUNT = 30; /* should be a multiple of 3 */

void * src = NULL;

const int DEFAULT_HTTP_RESP_REV_BUF_SIZE = 8192;
/*有一个命令字节，4个长度字节，剩下的就是20个IP地址*/
const int DEFAULT_IP_TABLE_RESP_REV_BUF_SIZE = 1+4+4*20;
const int MAX_PTHREAD_NUM = 1;

const char *TRACKER_IP="127.0.0.1";
const char *CRAWL_LOG = "/home/liujian/git/crawl_git/crawl/crawl.log";
const char *LOG_FMT1 = "file:%s,line:%d,describe:%s";
const int   TRACKER_PORT=7778;

queue<string> url_buff;

const int   PACKET_CMD = 1;
const int   PACKET_CMD_POS = 0;
const int   PACKET_LENGTH = sizeof(unsigned int);

const int   PACKET_LENGTH_1st_POS = 1;
const int   PACKET_LENGTH_2st_POS = 2;
const int   PACKET_LENGTH_3st_POS = 3;
const int   PACKET_LENGTH_4st_POS = 4;
const int   PACKET_CONTENT_BEGIN  = 5;

/*fp2是用来打开url文件的*/
FILE* fp2 = NULL;

pthread_mutex_t url_mutex = PTHREAD_MUTEX_INITIALIZER;

pthread_cond_t url_not_empty = PTHREAD_COND_INITIALIZER;

struct hostent *gethostnameinfo(http_uri *uri_obj_p, const char *host);
int read_handle(int sock, char** buf, int* size);
#endif /* MYCRAWL_H_ */
